import { defineStore } from 'pinia'

export type State = {
  logger: UniNamespace.LogManager
  // App info
  launchOptions: App.LaunchShowOption | null
  sceneNumber: string
  sceneName: string
  sucPage: string
  msg_uuid: string
  scanErrorKeys: Array<string>
  lastPage_path: string
  is_virtual: boolean
  scene: string
  hotSpotpwd: string
}
export type Getters = {}
export type Actions = {
  setLaunchOptions(options: App.LaunchShowOption | undefined): void
  setLastPagePath(): void
}

export const useGlobalStore = defineStore<'global', State, Getters, Actions>('global', {
  state: () => ({
    logger: uni.getLogManager({}),
    launchOptions: null,
    sceneNumber: '',
    sceneName: '',
    scene: '',
    hotSpotpwd: '',
    sucPage: '/pages/pairing/pairstep3/pairstep3',
    msg_uuid: '',
    scanErrorKeys: ['notLaunched', 'emptyType', 'energyTag', 'failure'],
    lastPage_path: '',
    is_virtual: false,
  }),
  getters: {},
  actions: {
    setLaunchOptions(options) {
      this.launchOptions = options || null
      this.logger.log(['App launch options: ', this.launchOptions])
    },
    setLastPagePath() {
      var pages = getCurrentPages()
      let currentPage = pages[pages.length - 1]
      this.lastPage_path = currentPage.route
    },
  },
})
